const ci = require('miniprogram-ci')
const path = require('path')

const mode = process.argv[2]?.split('=')[1] || ''

// 注意： new ci.Project 调用时，请确保项目代码已经是完整的，避免编译过程出现找不到文件的报错。
const project = new ci.Project({
  appid: 'wxc5e85177f6c4f22a',
  type: 'miniProgram',
  projectPath: path.resolve(__dirname,'./unpackage/dist/dev/mp-weixin'),
  privateKeyPath: path.resolve(__dirname,'./private.wxc5e85177f6c4f22a.key'),
  ignores: ['node_modules/**/*','.vite','uploadWxapp.js','private.wxc5e85177f6c4f22a.key','.hbuilderx'],
})


function upload() {
    ci.upload({
        project,
        version: '0.0.1',
        desc: '测试npm ci工具上传代码',
        setting: {
        es6: true,
        },
        onProgressUpdate: console.log,
    }).then(res=>{
        console.log('uploadResult:',res);
    })

}

 function preview() {
     ci.preview({
        project,
        desc: 'hello', // 此备注将显示在“小程序助手”开发版列表中
        setting: {
            es6: true,
            },
        qrcodeFormat: 'image',
        qrcodeOutputDest: path.resolve(__dirname,'./previewQrcode.jpg'),
        onProgressUpdate: console.log,
        // pagePath: 'pages/index/index', // 预览页面
        // searchQuery: 'a=1&b=2',  // 预览参数 [注意!]这里的`&`字符在命令行中应写成转义字符`\&`
    })
 }

function start() {
    switch (mode) {
        case 'preview':
            preview()
            break;

        default:
            upload()
            break;
    }
}

start()